package com.longteng.java.web;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

/**
 * Created by tianqing.wang
 * DATE : 2018/3/25
 * TIME : 上午12:36
 * PROJECT : web-lesson
 * PACKAGE : com.longteng.java.web
 *
 * @author <a href="mailto:celeskyking@163.com">tianqing.wang</a>
 */
@Configuration
//@Component
public class BeanConfiguration {


    @Bean
    public FastJsonHttpMessageConverter fastJsonHttpMessageConverter4(){
        FastJsonHttpMessageConverter fastJsonHttpMessageConverter =  new FastJsonHttpMessageConverter();
        fastJsonHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8));
        return fastJsonHttpMessageConverter;
    }




    @Bean
    public RestTemplate customRestTemplate(List<HttpMessageConverter<?>> httpMessageConverters){
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setConnectionRequestTimeout(3000);
        factory.setConnectTimeout(3000);
        factory.setReadTimeout(3000);
        RestTemplate restTemplate =  new RestTemplate(factory);
        restTemplate.setMessageConverters(httpMessageConverters);
        return restTemplate;
    }









}
